#ifndef __M_ECHO_H__
#define __M_ECHO_H__
#include "../reactor.hpp"
class EchoServer {
    public:
        EchoServer(bit_net::EventLoop *loop, int port):_server(loop, port) {
            _server.set_connected_callback(std::bind(&EchoServer::OnConnected, this, std::placeholders::_1));
            _server.set_message_callback(std::bind(&EchoServer::OnMessage, this, std::placeholders::_1, std::placeholders::_2));
        }
        void OnConnected(const bit_net::ConnectionPtr &conn) {
            DBG_LOG("new Connection:%p; socket:%d", conn.get(), conn->fd());
        }
        void OnMessage(const bit_net::ConnectionPtr &conn, bit_net::Buffer *buffer) {
            std::string str = buffer->retrieve_all_as_string();
            conn->send(str.c_str(), str.size());
            conn->shutdown();
        }
        void set_thread_count(int num) {
            return _server.set_thread_count(num);
        }
        void start() {
            return _server.start();
        }
    private:
        bit_net::TcpServer _server;
};

#endif